package main;

import java.awt.Component;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;

import javax.imageio.ImageIO;
import javax.swing.*;

import jobs.Aeroclept;
import jobs.Aquamancer;
import jobs.Gaian;
import jobs.Job;
import jobs.Paladin;
import jobs.Reaper;
import jobs.Vulcan;
import spells.Fireball;
import spells.Heal;
import creatures.Wolf;

public class IntroChooserPanel extends JFrame implements ActionListener {
	
	JRadioButton Fire = new JRadioButton("Vulcan");
	JRadioButton Water = new JRadioButton("Aquamancer");
	JRadioButton Earth = new JRadioButton("Gaian");
	JRadioButton Air = new JRadioButton("Aeroclept");
	JRadioButton Light = new JRadioButton("Paladin");
	JRadioButton Dark = new JRadioButton("Reaper");
	
	JButton next;
	JButton quit;
	
	static Job job;
	public static String name;
	JTextField nameInput;
	
	public IntroChooserPanel () {
		setSize(new Dimension(824,646));
		setVisible(true);
		
		getContentPane().setLayout(new BoxLayout(getContentPane(), BoxLayout.PAGE_AXIS));

		Fire.setSelected(true);
		
		ButtonGroup choices = new ButtonGroup();
		choices.add(Fire);
		choices.add(Water);
		choices.add(Earth);
		choices.add(Air);
		choices.add(Light);
		choices.add(Dark);

	    String FireBlurb = "A vulcan hailing from the land of Kaian.  He can deal large amounts of damage, but is very fragile.";
	    String WaterBlurb = "An aquamancer from Sephia.  A master spellcaster with weak physical attacks.";
	    String EarthBlurb = "A gaian from Theyr.  He is very tough physically, but is weak when it comes to mana.";
	    String AirBlurb = "An aeroclept hailing from Iter.  He is focused on movement, with fast, but weak attacks.";
	    String LightBlurb = "A paladin from Yvrin.  He is tough with slow attacks.";
	    String DarkBlurb = "A reaper from Oyven.  He can deal moderate damage with both his attacks and spells.";
	    
	    ElementLabel fire = new ElementLabel(Fire, FireBlurb);
	    ElementLabel water = new ElementLabel(Water, WaterBlurb);
	    ElementLabel earth = new ElementLabel(Earth, EarthBlurb);
	    ElementLabel air = new ElementLabel(Air, AirBlurb);
	    ElementLabel light = new ElementLabel(Light, LightBlurb);
	    ElementLabel dark = new ElementLabel(Dark, DarkBlurb);
	    
	    JLabel nameInputPrompt = new JLabel();
	    nameInputPrompt.setText("Enter a name for your character:");
	    
	    nameInput = new JTextField();
	    nameInput.setMaximumSize(new Dimension(100, 25));
	    
	    next = new JButton();
	    next.setText("Next");
	    next.addActionListener(this);
	    
	    quit = new JButton();
	    quit.setText("Quit");
	    quit.addActionListener(this);
	    
	    nameInputPrompt.setAlignmentX(Component.LEFT_ALIGNMENT);
	    nameInput.setAlignmentX(Component.LEFT_ALIGNMENT);
	    
	    next.setAlignmentX(Component.LEFT_ALIGNMENT);
	    quit.setAlignmentX(Component.LEFT_ALIGNMENT);

	    add(Box.createRigidArea(new Dimension(50, 0)));
	    
	    add(nameInputPrompt);
	    add(nameInput);
	    
		add(fire);
		add(water);
		add(earth);
		add(air);
		add(light);
		add(dark);
	    
		add(next);
		add(quit);
		
		this.setVisible(true);
		this.setResizable(false);
		this.setDefaultCloseOperation(EXIT_ON_CLOSE);
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public void setJob(Job job) {
		this.job = job;
	}

	public Job getJob() {
		return job;
	}
	
	public void actionPerformed(ActionEvent e) {
		if (e.getSource() == next){
			if (Fire.isSelected()) {
				job = new Vulcan(null);
			}
			else if (Water.isSelected()) {
				job = new Aquamancer(null);
			}
			else if (Earth.isSelected()) {
				job = new Gaian(null);
			}
			else if (Air.isSelected()) {
				job = new Aeroclept(null);
			}
			else if (Light.isSelected()) {
				job = new Paladin(null);
			}
			else if (Dark.isSelected()) {
				job = new Reaper(null);
			}
			name = nameInput.getText();
			IntroStart.launch();
			this.setVisible(false);
		}
		else if (e.getSource() == quit) {
			System.exit(0);
		}
	}
}